package com.ruoyi.web.controller.system;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.utils.mybatisPlus.SearchModel;
import com.ruoyi.system.domain.Question;
import com.ruoyi.system.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import java.util.List;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 问题记录Controller
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@Api(tags = "问题记录", description = "提供问题记录信息相关的 Rest API")
@RestController
@RequestMapping("/system/question")
public class QuestionController extends BaseController {
    @Resource
    private QuestionService questionService;

    /**
     * 查询问题记录列表
     */
    @ApiOperation(value = "查询问题记录列表",response = Question.class)
    @PreAuthorize("@ss.hasPermi('system:question:list')")
    @PostMapping("/list")
    public IPage<Question> list(@RequestBody SearchModel<Question> question){
        return questionService.page(question);
    }

    /**
     * 导出问题记录列表
     */
    @ApiOperation("导出问题记录列表")
    @PreAuthorize("@ss.hasPermi('system:question:export')")
    @Log(title = "问题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,  @RequestBody SearchModel<Question> question){
        IPage<Question> page = questionService.page(question);
        ExcelUtil<Question> util = new ExcelUtil<>(Question.class);
        util.exportExcel(response, page.getRecords(), "问题记录数据");
    }

    /**
     * 获取问题记录详细信息
     */
    @ApiOperation(value = "获取问题记录详细信息",response = Question.class)
    @PreAuthorize("@ss.hasPermi('system:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(questionService.selectQuestionById(id));
    }

    /**
     * 新增问题记录
     */
    @ApiOperation("新增问题记录")
    @PreAuthorize("@ss.hasPermi('system:question:add')")
    @Log(title = "问题记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Question question){
        return toAjax(questionService.insertQuestion(question));
    }

    /**
     * 修改问题记录
     */
    @ApiOperation("修改问题记录")
    @PreAuthorize("@ss.hasPermi('system:question:edit')")
    @Log(title = "问题记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Question question){
        return toAjax(questionService.updateQuestion(question));
    }

    /**
     * 删除问题记录
     */
    @ApiOperation("删除问题记录")
    @ApiImplicitParam(name="ids",value="ids 数组",paramType="form",dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('system:question:remove')")
    @Log(title = "问题记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids){
        return toAjax(questionService.deleteQuestionByIds(ids));
    }
}
